From 085f323f44fec1fbe793a9811a1cc90e981fbc0a Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Tue, 12 Oct 2021 09:12:43 -0600 Subject: [PATCH] accomodate the deletion of QDateTime::toTime_t in Qt6. --- src/core/datetime.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/core/datetime.h b/src/core/datetime.h index a334043fa..93b60b34f 100644 --- a/src/core/datetime.h +++ b/src/core/datetime.h @@ -23,6 +23,7 @@ #ifndef DATETIME_H_INCLUDED_ #define DATETIME_H_INCLUDED_ +#include #include #include @@ -59,7 +60,7 @@ public: // Temporary: Override the standard, also handle time_t 0 as invalid. bool isValid() const { - return date().isValid() && time().isValid() && toTime_t() > 0; + return QDateTime::isValid() && (toSecsSinceEpoch() != 0); } // Like toString, but with subsecond time that's included only when @@ -71,6 +72,18 @@ public: return toUTC().toString(QStringLiteral("yyyy-MM-ddTHH:mm:ssZ")); } } + + // QDateTime::toTime_t was deprecated in Qt5.8, and deleted in Qt6. + uint32_t toTime_t() const { + if (!QDateTime::isValid()) { + return -1; + } + long long secs_since_epoch = toSecsSinceEpoch(); + if ((secs_since_epoch < 0) || (secs_since_epoch > 0xfffffffe)) { + return -1; + } + return secs_since_epoch; + } }; } // namespace gpsbabel -- 2.30.2